package cn.xopencode.securityservice.service.activity.impl;

import cn.hutool.core.util.IdUtil;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.securityservice.convert.activity.ActivityConvert;
import cn.xopencode.securityservice.convert.suggest.SuggestConvert;
import cn.xopencode.securityservice.dal.mysql.dataobject.activity.ActivityDO;
import cn.xopencode.securityservice.dal.mysql.dataobject.suggest.SuggestDO;
import cn.xopencode.securityservice.dal.mysql.mapper.activity.ActivityMapper;
import cn.xopencode.securityservice.dal.mysql.mapper.suggest.SuggestMapper;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityCreateReqDTO;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityPageReqDTO;
import cn.xopencode.securityservice.rpc.activity.dto.ActivityRespDTO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestCreateReqDTO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestPageReqDTO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestRespDTO;
import cn.xopencode.securityservice.service.activity.ActivityService;
import cn.xopencode.securityservice.service.suggest.SuggestService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;

/**
 * 安全活动与技能比武情况 Service 实现
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    /**
     * 添加安全活动与技能比武情况
     */
    @Override
    public Integer createActivity(ActivityCreateReqDTO createDTO) {
        ActivityDO activityDO = ActivityConvert.INSTANCE.convert(createDTO);
        activityDO.setId(IdUtil.objectId());
        activityDO.setCreateTime(new Date());
        return activityMapper.insert(activityDO);
    }

    /**
     * 分页查询安全活动与技能比武情况
     */
    @Override
    public PageResult<ActivityRespDTO> pageActivity(ActivityPageReqDTO pageReqDTO) {
        IPage<ActivityDO> activityDO = activityMapper.selectPage(pageReqDTO.setSorts(Collections.singletonList(ActivityPageReqDTO.ACTIVITYTIME_DESC)));
        return ActivityConvert.INSTANCE.convertPage(activityDO);
    }

    /**
     * 根据编号查询安全活动与技能比武情况
     */
    @Override
    public ActivityRespDTO getActivity(String activityId) {
        ActivityDO activityDO = activityMapper.selectById(activityId);
        return ActivityConvert.INSTANCE.convert(activityDO);
    }
}

